package com.xxx.coll;

import java.util.Objects;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/20  16:19
 * @Copyright
 */
public class worker implements Comparable{
    private String name;
    private int age;

    public worker() {
    }

    public worker(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        System.out.println(this);
        System.out.println("equals");
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        worker worker = (worker) o;
        return age == worker.age && name.equals(worker.name);
    }

    @Override
    public int hashCode() {
        //System.out.println(this);
        System.out.println("hashCode");
        return Objects.hash(name, age);
    }

    @Override
    public int compareTo(Object o) {//1.排序，2.判断是否相等
        //System.out.println("compareTo");
        //System.out.println(this.name);
        worker worker = (worker)o;
        //System.out.println(worker.name);
        return this.name.compareTo(worker.name);

    }
}
